//const download = require("download-git-repo"); // 用于下载远程仓库至本地 支持GitHub、GitLab、Bitbucket
//const ora = require("ora"); // 用于命令行上的加载效果
const path = require("path");
const { getChoicesURLs } = require("../config/download");
//const TEMP_NAME = "temp"; // 模板的临时存储目录
const t = require("../config/dict");
const { fetchRemote } = require("../lib/utils");

module.exports = function (target, url, dir) {
  dir = dir || path.join(".", target.metadata.projectDir);
  return getChoicesURLs().then((choicesURLs) => {
    const config = choicesURLs;

    return new Promise((resolve, reject) => {
      const type = target.metadata.projectType[0];
      url =
        url ||
        "direct:" + config[target.metadata.projectTechnologyStack][type].url;
      fetchRemote(url, dir, target, [t(target.lang, "拉取数据")])
        .then((json) => {
          resolve(json);
        })
        .catch((err) => reject(err));
    });
  });
};
